/*系统公共的控件、组件 调用的JS*/

var WIDGET_PATH_PREFIX = ctx + "system/widget/";

var WASP_WIDGET = {
	// 初始化select的值
	initializeSelectVal : function(selId, selVal, selText) {
		$('#' + selId).html('');
		
		var multiple = $('#' + selId).attr("multiple");
		selVal = selVal || $('#' + selId).attr("val");
		selText = selText || $('#' + selId).attr("text");
		if (selVal != undefined && selVal != "") {
			if (multiple) {// 多选
				var vals = selVal.split(",");
				var txts = selText.split(",");
				if (vals.length != txts.length) {
					return;
				}
				for (var i = 0; i < vals.length; i++) {
					if(fiterRepeat(vals[i])){
						var option = $('<option selected="selected" value="' + vals[i] + '" >' + txts[i] + '</option>');
						$('#' + selId).append(option).trigger('change');
					}
				}
			} else {
				var option = $('<option selected="selected" value="' + selVal + '" >' + selText + '</option>');
				$('#' + selId).append(option).trigger('change');
			}
		} else {
			$('#' + selId).val(null).trigger('change');
		}
		//判断是否存在重复的值
		function fiterRepeat(val){
			var result =true;
			if($('#' + selId).find("option").length != 0){
				$('#' + selId).find("option").each(function(){
					if($(this).val()===val)
						result = false;
				});
			}
			return result;
		}
	},
	initializeSelectStyle: function() {
		var selects = $(".form-item-group").find("select");
		$.each(selects, function() {
			var id = $(this).attr("id");
			var placeholder = $(this).attr("placeholder");
			if(id && id != 'undefined') {
				if(!placeholder || placeholder == 'undefined') {
					placeholder = $(this).parent().prev().html().replace("：","").replace(":","");
				}
				$('#' + id).select2({placeholder: placeholder});
			}
		});
		
		var inputs = $(".form-item-group:not(:hidden)").find("input");
		$.each(inputs, function() {
			var id = $(this).attr("id");
			var placeholder = $(this).attr("placeholder");
			if(id && id != 'undefined') {
				if(!placeholder || placeholder == 'undefined') {
					placeholder = $(this).parent().prev().html().replace("：","").replace(":","");
				}
				$('#' + id).attr("placeholder", placeholder);
			}
		});
	},
	// 全部人员
	triggerSelectOnEmpId : function(managerId, option) {
		var multiple = false;
		if (option && option.multiple) {
			multiple = option.multiple;
		}
		var placeholder = $(managerId).attr("placeholder");
		if (placeholder == null || placeholder == '' || placeholder == 'undefind') {
			placeholder = "请选择";
		}
		$(managerId).select2({
			language:"zh-CN",
			multiple : multiple,
			placeholder : placeholder,
			ajax : {
				url : WIDGET_PATH_PREFIX + "queryMatchUserInfoList.do",
				delay : 400,
				type : "POST",
				data : function(params) {
					var query;
					if (params.term == null || params.term == '' || params.term == 'undefind') {
						query = {
							assistantNM : ""
						};
					} else {
						if (option) {// 自定义参数条件
							query = {
									assistantNM : params.term,
									queryDimission : option.queryDimission,
									cleanDele : option.cleanDele
							};
						} else {
							query = {
									assistantNM : params.term
						    };
						}
					}
					return query;
				},
				dataType : "json",
				processResults : function(data) {
					var results = $.map(data, function(obj) {
						var path = "";
						if (obj.titleName != null) {
							path = path  + obj.titleName;
						}
						if(obj.secondOrgname != null){
							path = path + "/"+ obj.secondOrgname;
						}else if(obj.orgName != null) {
							path = path + "/"+ obj.orgName;
						}
						return {
							id : obj.empID,
							text : obj.empName,
							path : path
						};
					});
					return {
						results : results
					};
				}
			},
			cache : true,
			templateResult : function(obj) {
				if(obj.path) {
					return $('<span data-html="true" ><strong>'+obj.text+'</strong>/' + obj.path + '</span>').tooltip();
				} else {
					return $('<span data-html="true" ><strong>'+obj.text+'</strong></span>').tooltip();
				}
			},
			templateSelection : function(obj) {
				return $('<span data-html="true" >' + obj.text + '</span>').tooltip();
			}

		});
	},
	// 部门
	triggerSelectOnDeptId : function(deptId, option) {
		var _placeholder = $('#' + deptId).attr("placeholder");
		if (_placeholder == null || _placeholder == '' || _placeholder == 'undefind') {
			_placeholder = "部门";
		}
		$('#' + deptId).select2({
			language:"zh-CN",
			placeholder : _placeholder,
			multiple : (option && option.multiple) || false,
			ajax : {
				url : WIDGET_PATH_PREFIX + "queryMatchDepartmentList.do",
				dataType : "json",
				type : "POST",
				delay : 400,
				data : function(params) {
					var query ;
					if (params.term == null || params.term == '' || params.term == 'undefind') {
						query = {
								orgName : ""
						};
					} else {					
						if (option) {// 自定义参数条件
							query = {
								orgName : params.term,
								isvalid : option.isvalid,
								leavedept : option.leavedept
							};
						} else {
							query = {
								orgName : params.term
						    };
						}
					}
					return query;
				},
				processResults : function(data) {
					var results = $.map(data, function(obj) {
						var path = "",text="",idx;				
						text = obj.orgname;
						idx = obj.orgid;
						path = obj.orgnamePath;
						return {
							id : idx,
							text : text,
							path : path
						};
					});
					return {
						results : results
					};
				}
			},
			cache : true,
			templateResult : function(obj) {
				if(obj.path==''||obj.path ==null){
					return $('<span data-html="true" ><strong>'+obj.text+'</strong></span>').tooltip();
				}else{
					return $('<span data-html="true" >' + obj.path + '</span>').tooltip();
				}
			},
			templateSelection : function(obj) {
				return $('<span data-html="true" >' + obj.text + '</span>').tooltip();
			}

		});
	},
	// 一级部门
	triggerSelectOnFirstDeptId : function(deptId, option) {
		var _placeholder = $('#' + deptId).attr("placeholder");
		if (_placeholder == null || _placeholder == '' || _placeholder == 'undefind') {
			_placeholder = "部门";
		}
		$('#' + deptId).select2({
			language:"zh-CN",
			placeholder : _placeholder,
			multiple : (option && option.multiple) || false,
			ajax : {
				url : WIDGET_PATH_PREFIX + "queryMatchFirstDeptList.do",
				dataType : "json",
				type : "POST",
				delay : 400,
				data : function(params) {
					var query;
					if (params.term == null || params.term == '' || params.term == 'undefind') {
						query = {
								orgName : ""
						};
					} else {
						if (option) {// 自定义参数条件
							query = {
								orgName : params.term,
								isvalid : option.isvalid,
								leavedept : option.leavedept
							};
						} else {
							query = {
								orgName : params.term
						    };
						}
					}
					return query;
				},
				processResults : function(data) {
					var results = $.map(data, function(obj) {
						var path = "",text="",idx;
						text = obj.orgname;
						idx = obj.orgid;
						path = obj.orgnamePath;
						return {
							id : idx,
							text : text,
							path : path
						};
					});
					return {
						results : results
					};
				}
			},
			cache : true,
			templateResult : function(obj) {
				if(obj.path==''||obj.path ==null){
					return $('<span data-html="true" ><strong>'+obj.text+'</strong></span>').tooltip();
				}else{
					return $('<span data-html="true" >' + obj.path + '</span>').tooltip();
				}
			},
			templateSelection : function(obj) {
				return $('<span data-html="true" >' + obj.text + '</span>').tooltip();
			}
			
		});
	},
	triggerOrgChilds: function(currentId, reOrgId) {
		var _placeholder = $('#' + currentId).attr("placeholder");
		$('#' + currentId).select2({
			tags:true,
			language : "zh-CN",
			placeholder : _placeholder || '请选择',
			maximumSelectionLength:1,
			multiple : true,
			ajax : {
				url : WIDGET_PATH_PREFIX + "queryOrgChilds.do",
				type : "POST",
				delay : 250,
				data : function(params) {
					var query = {
						reOrgId : reOrgId,
						limit : 10
					};
					
					if (params.term == null || params.term == '' || params.term == 'undefind') {// 用户输入的查询条件
						query.orgName = "";
					} else {
						query.orgName = params.term.trim();
					}
					return query;
				},
				dataType : "json",
				processResults : function(data) {
					var results = $.map(data, function(obj) {
						return {
							id : obj.orgId + "_" + obj.orgName,
							text : obj.orgName
						}
					});
					return {
						results : results
					};
				}
			},
			cache : true,
			templateResult : function(obj) {
				if (obj.newTag) {
					return $('<span data-html="true"><span style="color:red;"><b>(新增)</b></span> ' + obj.text + '</span>');
				} else if (obj.text != '搜索中…') {
					return $('<span data-html="true"><span style="color:blue;"><b>(现有)</b></span> ' + obj.text + '</span>');
				}
				return null;
			},
			createTag: function (params) {
				var fvps = $('#' + currentId).val(); 
				if(fvps) {
					if($.inArray("NewTag_" + $.trim(params.term), fvps) != -1) {  // 已经存在这个标签了
						return undefined;
					}
				}
			    var term = $.trim(params.term);
			    if (term === '') {
			      return null;
			    }
			    return {
			    	id: "NewTag_" + term,  // 标识一下是由用户新增的，后台判断的时候用
			    	text: term,
			    	newTag: true // add additional parameters
			    };
		    }
		});
	},
	triggerTitleChilds: function(currentId, orgId) {
		var _placeholder = $('#' + currentId).attr("placeholder");
		$('#' + currentId).select2({
			tags:true,
			language : "zh-CN",
			placeholder : _placeholder || '请选择',
			maximumSelectionLength:1,
			multiple : true,
			ajax : {
				url : WIDGET_PATH_PREFIX + "queryTitleChilds.do",
				type : "POST",
				delay : 250,
				data : function(params) {
					var query = {
						orgId : orgId,
						limit : 10
					};
					
					if (params.term == null || params.term == '' || params.term == 'undefind') {// 用户输入的查询条件
						query.titleName = "";
					} else {
						query.titleName = params.term.trim();
					}
					return query;
				},
				dataType : "json",
				processResults : function(data) {
					var results = $.map(data, function(obj) {
						return {
							id : obj.titleId + "_" + obj.titleName,
							text : obj.titleName
						}
					});
					return {
						results : results
					};
				}
			},
			cache : true,
			templateResult : function(obj) {
				if (obj.newTag) {
					return $('<span data-html="true"><span style="color:red;"><b>(新增)</b></span> ' + obj.text + '</span>');
				} else if (obj.text != '搜索中…') {
					return $('<span data-html="true"><span style="color:blue;"><b>(现有)</b></span> ' + obj.text + '</span>');
				}
				return null;
			},
			createTag: function (params) {
				var fvps = $('#' + currentId).val(); 
				if(fvps) {
					if($.inArray("NewTag_" + $.trim(params.term), fvps) != -1) {  // 已经存在这个标签了
						return undefined;
					}
				}
			    var term = $.trim(params.term);
			    if (term === '') {
			      return null;
			    }
			    return {
			    	id: "NewTag_" + term,  // 标识一下是由用户新增的，后台判断的时候用
			    	text: term,
			    	newTag: true // add additional parameters
			    };
		    }
		});
	},
	// 岗位
	triggerSelectOnPost : function(postId) {
		var _placeholder = $('#' + postId).attr("placeholder");
		if (_placeholder == null || _placeholder == '' || _placeholder == 'undefind') {
			_placeholder = "岗位";
		}
		$('#' + postId).select2({
			language:"zh-CN",
			placeholder : _placeholder,
			multiple : false,
			ajax : {
				url : WIDGET_PATH_PREFIX + "queryMatchPost.do",
				type : "POST",
				delay : 400,
				data : function(params) {
					var query;
					if (params.term == null || params.term == '' || params.term == 'undefind') {
						query = {
							postTitle : ""
						};
					} else {
						query = {
							postTitle : params.term
						};
					}
					return query;
				},
				dataType : "json",
				processResults : function(data) {
					var results = $.map(data, function(obj) {
						return {
							id : obj.postId,
							text : obj.postTitle
						};
					});
					return {
						results : results
					};
				}
			},
			cache : true,
			templateSelection : function(obj) {
				console.info(obj);
				return $('<span data-html="true" >' + obj.text + '</span>').tooltip();
			}
		});
	},
	// 操作角色
	triggerSelectOnOperRole : function(operRoleId) {
		var _placeholder = $('#' + operRoleId).attr("placeholder");
		if (_placeholder == null || _placeholder == '' || _placeholder == 'undefind') {
			_placeholder = "操作角色";
		}
		$('#' + operRoleId).select2({
			language:"zh-CN",
			placeholder : _placeholder,
			multiple : false,
			ajax : {
				url : WIDGET_PATH_PREFIX + "queryMatchOperRole.do",
				type : "POST",
				delay : 400,
				data : function(params) {
					var query;
					if (params.term == null || params.term == '' || params.term == 'undefind') {
						query = {
							roleName : ""
						};
					} else {
						query = {
							roleName : params.term
						};
					}
					return query;
				},
				dataType : "json",
				processResults : function(data) {
					var results = $.map(data, function(obj) {
						return {
							id : obj.roleId,
							text : obj.roleName
						};
					});
					return {
						results : results
					};
				}
			},
			cache : true,
			templateSelection : function(obj) {
				console.info(obj);
				return $('<span data-html="true" >' + obj.text + '</span>').tooltip();
			}
		});
	},
	triggerSelectOnMenu : function(menuId) {
		var _placeholder = $('#' + menuId).attr("placeholder");
		if (_placeholder == null || _placeholder == '' || _placeholder == 'undefind') {
			_placeholder = "菜单/按钮";
		}
		$('#' + menuId).select2({
			language:"zh-CN",
			placeholder : _placeholder,
			multiple : false,
			ajax : {
				url : WIDGET_PATH_PREFIX + "queryMatchMenu.do",
				type : "POST",
				delay : 400,
				data : function(params) {
					var query;
					if (params.term == null || params.term == '' || params.term == 'undefind') {
						query = {
							menuNM : ""
						};
					} else {
						query = {
							menuNM : $.trim(params.term)
						};
					}
					return query;
				},
				dataType : "json",
				processResults : function(data) {
					var results = $.map(data, function(obj) {
						return {
							id : obj.menuId,
							text : obj.name
						}
					});
					return {
						results : results
					};
				}
			},
			cache : true,
			templateSelection : function(obj) {
				console.info(obj);
				return $('<span data-html="true" >' + obj.text + '</span>').tooltip();
			}
		});
	},
	// 绑定ICheck样式 modify by weicb：支持jquery选择器个性化绑定ifChecked、ifUnchecked事件
	//  modify by weicb：2016-06-13增加参数noValid 是否不需要校验 不需要表单校验传入true
	triggerICheck : function(selector,funcChecked,funcUnchecked,noValid) {
		if (selector && typeof selector==="string") {//支持jquery选择器个性化绑定
			$(selector).iCheck({
				checkboxClass : 'icheckbox_square-green',
			}).on('ifChecked', function() {
				if(funcChecked && typeof funcChecked==="function")
					funcChecked(this.value);
				if(!noValid)
					$(this).valid && $(this).valid();
			}).on('ifUnchecked', function() {
				if(funcUnchecked && typeof funcUnchecked==="function")
					funcUnchecked(this.value);
				if(!noValid)
					$(this).valid && $(this).valid();
			});
		}else{//不传参数默认绑定页面所有的checkbox
			$('[type=checkbox]').iCheck({
				checkboxClass : 'icheckbox_square-green',
			}).on('ifChecked', function() {
				if(!noValid)
					$(this).valid && $(this).valid();
			}).on('ifUnchecked', function() {
				if(!noValid)	
					$(this).valid && $(this).valid();
			});
		}
	},
	// 绑定IRadio样式 modify by weicb：支持jquery选择器个性化绑定ifChecked、ifUnchecked事件
	//  modify by weicb：2016-06-13增加参数noValid 是否不需要校验 不需要表单校验传入true
	triggerIRadio : function(selector,funcChecked,funcUnchecked,noValid) {
		if (selector && typeof selector==="string") {//jquery选择器个性化
			$(selector).iCheck({
				radioClass : 'iradio_square-green',
			}).on('ifChecked', function() {
				if(funcChecked && typeof funcChecked==="function")
					funcChecked(this.value);
				if(!noValid)
					$(this).valid && $(this).valid();
			}).on('ifUnchecked', function() {
				if(funcUnchecked && typeof funcUnchecked==="function")
					funcUnchecked(this.value);
				if(!noValid)
					$(this).valid && $(this).valid();
			});
		}else{//不传参数默认绑定页面所有的radio
			$('[type=radio]').iCheck({
				radioClass : 'iradio_square-green',
			}).on('ifChecked', function() {
				if(!noValid)
					$(this).valid && $(this).valid();
			}).on('ifUnchecked', function() {
				if(!noValid)
					$(this).valid && $(this).valid();
			});
		}
	},
	// 绑定日期控件 YYYY-MM-DD样式
	triggerDateStyleWithYMD : function(domSelect) {
		var doms = $(domSelect);
		for(var i = 0; i < doms.length; i++) {
			$(doms[i]).datepicker({
				weekStart: 1,
				format: "yyyy-mm-dd",
				todayBtn: "linked",
				clearBtn: true,
				language: "zh-CN",
				autoclose: true,
				todayHighlight: true
			});
		}
	},
	// 绑定日期控件 YYYY-MM-DD样式
	triggerYMDDateStyle : function(selector, option) {
		var todayBtn = "linked";
		if (option && option.todayBtn !== null) {
			todayBtn = option.todayBtn;
		}
		var todayHighlight = true;
		if (option && option.todayHighlight !== null) {
			todayHighlight = option.todayHighlight;
		}
		
		$(selector).datepicker({
			weekStart: 1,
			format: option.format,
			forceParse: option.forceParse,
			todayBtn: todayBtn,
			clearBtn: true,
			language: "zh-CN",
			autoclose: true,
			todayHighlight: todayHighlight,
		    daysOfWeekDisabled: option.daysOfWeekDisabled || "",
		    startDate: option.startDate || ''
		});
	},
	// 绑定日期控件 YYYY-MM-DD样式(只能选指定日期之前)
	triggerDateStyleYMDEndDate : function(selector, option) {
		var todayBtn = "linked";
		if (option && option.todayBtn !== null) {
			todayBtn = option.todayBtn;
		}
		var todayHighlight = true;
		if (option && option.todayHighlight !== null) {
			todayHighlight = option.todayHighlight;
		}
		var format = "yyyy-mm-dd";
		if (option && option.format !== null) {
			format = option.format;
		}
		
		$('#' + selector).datepicker({
			weekStart: 1,
			format: format,
			forceParse: option.forceParse,
			todayBtn: todayBtn,
			clearBtn: true,
			language: "zh-CN",
			autoclose: true,
			todayHighlight: todayHighlight,
		    daysOfWeekDisabled: option.daysOfWeekDisabled || "",
		    endDate: option.endDate || ''
		});
	},
	// 绑定日期控件 YYYY-MM样式
	triggerDateStyleWithYM : function(dateId) {
		$('#' + dateId).datepicker({
			minViewMode: 1,
	        format: "yyyy-mm",
	        todayBtn: "linked",
	        clearBtn: true,
	        language: "zh-CN",
	        autoclose: true,
	        todayHighlight: true  	
	    });
	},
	// 绑定日期控件 YYYY样式
	triggerDateStyleWithY : function(dateId) {
		$('#' + dateId).datepicker({
			minViewMode: 1,
	        format: "yyyy",
	        todayBtn: "linked",
	        clearBtn: true,
	        language: "zh-CN",
	        autoclose: true,
	        todayHighlight: true  	
	    });
	},
	// 绑定日期控件 YYYY样式
	triggerDateStyleWithYYYY : function(dateId) {
		$('#' + dateId).datepicker({
			startDate: '1990',
			minViewMode: 2,
			startView: 2,
	        format: "yyyy",
	        todayBtn: "linked",
	        clearBtn: true,
	        language: "zh-CN",
	        autoclose: true,
	        todayHighlight: true  	
	    });
	},
	
	// 绑定日期时间控件，没有秒钟，并且要由用户传入起始时间
	triggerDateTimeStyleWithoutSSByStart : function(dateId, time) {
		$('#' + dateId).datetimepicker({
			weekStart: 1,
			startDate:time,
			format: "yyyy-mm-dd hh:ii",
		    todayBtn: "linked",
		    clearBtn: true,
		    language: "zh-CN",
		    autoclose: true,
		    todayHighlight: true,
		    fontAwesome: true
	    });
	},
	// 绑定日期时间控件，没有秒钟
	triggerDateTimeStyleWithoutSS : function(domSelect) {
		var doms = $(domSelect);
		for(var i = 0; i < doms.length; i++) {
			$(doms[i]).datetimepicker({
				weekStart: 1,
				format: "yyyy-mm-dd hh:ii",
			    todayBtn: "linked",
			    clearBtn: true,
			    language: "zh-CN",
			    autoclose: true,
			    todayHighlight: true,
			    fontAwesome: true
		    });
		}
	},
	// 绑定日期时间控件
	triggerDateTimeStyle : function(dateId) {
		$('#' + dateId).datetimepicker({
			weekStart: 1,
			format: "yyyy-mm-dd hh:ii:ss",
		    todayBtn: "linked",
		    clearBtn: true,
		    language: "zh-CN",
		    autoclose: true,
		    todayHighlight: true,
		    fontAwesome: true
	    });
	},
	triggerKindEditor : function(descId,isvalid) {
		KindEditor.ready(function (K) {
			var editor = K.create('#'+descId, {
				allowFileManager : false,
				//autoHeightMode : true,
				minWidth:670,
				afterCreate : function() {
					this.sync();
				},
				afterChange:function(){
					this.sync();
					var $this = $('#'+descId);
					if(isvalid){
						$this.valid && $this.valid();
					}
				},
				afterBlur:function(){
					this.sync();
					var $this = $('#'+descId);
					if(isvalid){
						$this.valid && $this.valid();
				    }
				},
				fileManagerJson : '/scbp/kingEditor/fileManagerJson.do',
				uploadJson : '/scbp/kingEditor/uploadJson.do'
			});
			
		});
	},
	// 绑定日期范围控件
	triggerDateRangeStyle : function(dateId) {
		$('#' + dateId).daterangepicker({
			autoUpdateInput : false,
			alwaysShowCalendars : true,
			ranges : {
				'今天' : [ moment(), moment() ],
				'昨天' : [ moment().subtract(1, 'days'), moment().subtract(1, 'days') ],
				'前一周' : [ moment().subtract(6, 'days'), moment() ],
				'当月' : [ moment().startOf('month'), moment().endOf('month') ],
				'截止今天' : [ moment('1990/01/01', "YYYY/MM/DD"), moment() ],
				'从今天起' : [ moment(), moment('2200/01/01', "YYYY/MM/DD") ]
			},
			locale : {
				format : 'YYYY/MM/DD',
				separator : ' - ',
				cancelLabel : '清除'//Clear
			}
		});
		$('#' + dateId).on('apply.daterangepicker', function(ev, picker) {
			$(this).val(picker.startDate.format('YYYY/MM/DD') + ' - ' + picker.endDate.format('YYYY/MM/DD'));
		});
		$('#' + dateId).on('cancel.daterangepicker', function(ev, picker) {
			$(this).val('');
		});
	},
	
	// 注册清空事件，必须是button[type=reset]
	registerResetClearEvent : function() {
		$('button[type=reset]').on('click', function() {
			var $parent = $(this).closest('form, .form-col-panel, .form-multi-col-panel');
			var $select = $parent.find('.use-select2').val(null);

			$parent.find('input, textarea, select').val(null);
			setTimeout(function() {
				$select.trigger('change.select2');
			}, 0);
		});

	},
	
	// 注册查询条件输入时回车事件
	registerEnterQueryEvent : function(callback) {
		$('.form-item .form-input input').keydown(function(e){
			if(e.keyCode==13){
				if(callback && typeof callback==="function") {
					callback(true);
				} else {
					// 默认查询函数
					queryByCondtion(true);
				}
			}
		});
	},
	triggerSelectOnDicts : function(element,option) {
		var _placeholder=element.attr("placeholder");
		if(_placeholder== null || _placeholder== ''
			|| _placeholder == 'undefind'){
			_placeholder="数据字典";
		}
		element.select2(
				{
					language : "zh-CN",
					placeholder : _placeholder,
					multiple : false,
					ajax : {
						url : WIDGET_PATH_PREFIX + "queryMatchDictList.do",
						type : "POST",
						delay : 400,
						data : function(params) {
							var query={};
							if(option){//自定义参数条件
								query=option;
								if(option.txt_dctFathType){
									query.dctFathType=$("#"+option.txt_dctFathType).val();
								}
							}
							if (params.term == null || params.term == ''
									|| params.terdictm == 'undefind') {//用户输入的查询条件
								query.dctName = "";
							} else {
								query.dctName = params.term;
							}
							return query;
						},
						dataType : "json",
						processResults : function(data) {
							var results = $.map(data, function(obj) {
								return {
									id : obj.dctValue,
									text : obj.dctName
								};
							});
							return {
								results : results
							};
						}
					},
					cache : true
					
				});
	},
	// 系列产品
	triggerCustPrdInfoSelect : function(prdCode,option) {
		var multiple = false;
		if (option && option.multiple) {
			multiple = option.multiple;
		}
		var _placeholder = $('#' + prdCode).attr("placeholder");
		if (_placeholder == null || _placeholder == '' || _placeholder == 'undefind') {
			_placeholder = "产品名称";
		}
		$('#' + prdCode).select2({
			language:"zh-CN",
			placeholder : _placeholder,
			multiple : multiple,
			ajax : {
				url : WIDGET_PATH_PREFIX + "custRegisQueryPrdInfoList.do",
				type : "POST",
				delay : 400,
				data : function(params) {
					var query;
					if (params.term == null || params.term == '' || params.term == 'undefind') {
						query = {
								prdName : ""
						};
					} else {
						
						if (option) {// 自定义参数条件
							query = {
									assistantNM : params.term,
									queryDimission : option.queryDimission,
									cleanDele : option.cleanDele
							};
							
							if (option.selectType == 'prdName') {
								query = {
										prdName : params.term
								};
							}
						}else{
							query = {
									prdName : params.term
							};
						}
						
					}
					return query;
				},
				dataType : "json",
				processResults : function(data) {
					var results = $.map(data, function(obj) {
						return {
							id : obj.prjcode,
							text : obj.prjsname
						};
					});
					return {
						results : results
					};
				}
			},
			cache : true,
			templateSelection : function(obj) {
				return $('<span data-html="true" >' + obj.text + '</span>').tooltip();
			}
		});
	},

	// 招商财富产品线产品
	triggerPrdLineSelect : function(subPrdCode,option) {
		
		var multiple = false;
		if (option && option.multiple) {
			multiple = option.multiple;
		}
		var _placeholder = $('#' + subPrdCode).attr("placeholder");
		if (_placeholder == null || _placeholder == '' || _placeholder == 'undefind') {
			_placeholder = "产品名称";
		}
		$('#' + subPrdCode).select2({
			language:"zh-CN",
			placeholder : _placeholder,
			multiple : multiple,
			ajax : {
				url : WIDGET_PATH_PREFIX + "prdLineInfoList.do",
				type : "POST",
				delay : 400,
				data : function(params) {
					var query;
					if (params.term == null || params.term == '' || params.term == 'undefind') {
						query = {
								prdName : ""
						};
					} else {
						
						if (option) {// 自定义参数条件
							query = {
									assistantNM : params.term,
									queryDimission : option.queryDimission,
									cleanDele : option.cleanDele
							};
							
							if (option.selectType == 'subFundSname') {
								query = {
										subFundSname : params.term
								};
							}
						}else{
							query = {
									subFundSname : params.term
							};
						}
						
					}
					return query;
				},
				dataType : "json",
				processResults : function(data) {
					var results = $.map(data, function(obj) {
						return {
							id : obj.subPrdCode,
							text : obj.subFundSname
						};
					});
					return {
						results : results
					};
				}
			},
			cache : true,
			templateSelection : function(obj) {
				return $('<span data-html="true" >' + obj.text + '</span>').tooltip();
			}
		});
	},

	//系列产品
	triggerPrdInfoSelect : function(prdCode,option) {
		var multiple = false;
		if (option && option.multiple) {
			multiple = option.multiple;
		}
		var _placeholder = $('#' + prdCode).attr("placeholder");
		if (_placeholder == null || _placeholder == '' || _placeholder == 'undefind') {
			_placeholder = "产品名称";
		}
		$('#' + prdCode).select2({
			language:"zh-CN",
			placeholder : _placeholder,
			multiple : multiple,
			ajax : {
				url : WIDGET_PATH_PREFIX + "queryPrdInfoList.do",
				type : "POST",
				delay : 400,
				data : function(params) {
					var query;
					if (params.term == null || params.term == '' || params.term == 'undefind') {
						query = {
							prjSname : "",
							manageCompany: option ? option.manageCompany : ""
						};
					} else {
						
						if (option) {// 自定义参数条件
							query = {
									prjSname : params.term,
									manageCompany: option.manageCompany
							};
							
							if (option.selectType == 'prdName') {
								query = {
									prjSname : params.term,
									manageCompany: option.manageCompany
								};
							}
						}else{
							query = {
								prjSname : params.term,
							};
						}
						
					}
					return query;
				},
				dataType : "json",
				processResults : function(data) {
					var results = $.map(data, function(obj) {
						return {
							id : obj.prjcode,
							text : obj.prjsname
						};
					});
					return {
						results : results
					};
				}
			},
			cache : true,
			templateSelection : function(obj) {
				return $('<span data-html="true" >' + obj.text + '</span>').tooltip();
			}
		});
	},
	//产品名称下拉
	triggerProductInfoSelect : function(prjCode,param,option) {
		var multiple = false;
		if (option && option.multiple) {
			multiple = option.multiple;
		}
		var _placeholder = $('#' + prjCode).attr("placeholder");
		if (_placeholder == null || _placeholder == '' || _placeholder == 'undefind') {
			_placeholder = "产品名称";
		}
		$('#' + prjCode).select2({
			language:"zh-CN",
			placeholder : _placeholder,
			multiple : multiple,
			ajax : {
				url : WIDGET_PATH_PREFIX + "queryProductInfoList.do",
				type : "POST",
				delay : 400,
				data : function(params) {
					var query;
					if (params.term == null || params.term == '' || params.term == 'undefind') {
						query = {
							prjcode:param,
							fundsname : ""
						};
					} else {
						if (option) {// 自定义参数条件
							query = {
									assistantNM : params.term,
									queryDimission : option.queryDimission,
									cleanDele : option.cleanDele
							};
							
							if (option.selectType == 'prdName') {
								query = {
										prjcode:param,
										fundsname : params.term
								};
							}
						}else{
							query = {
									prjcode:param,
									fundsname : params.term
							};
						}
						
					}
					return query;
				},
				dataType : "json",
				processResults : function(data) {
					var results = $.map(data, function(obj) {
						return {
							id : obj.prdcode,
							text : obj.fundsname
						};
					});
					return {
						results : results
					};
				}
			},
			cache : true,
			templateSelection : function(obj) {
				return $('<span data-html="true" >' + obj.text + '</span>').tooltip();
			}
		});
	},
	//子产品名称下拉
	triggerSubProductInfoSelect : function(prdCode,param,option) {
		var multiple = false;
		if (option && option.multiple) {
			multiple = option.multiple;
		}
		var url = "queryMatchSubPrdInfoList.do";
		if (option && option.url) {
			url = option.url;
		}
		
		var _placeholder = $('#' + prdCode).attr("placeholder");
		if (_placeholder == null || _placeholder == '' || _placeholder == 'undefind') {
			_placeholder = "子产品名称";
		}
		$('#' + prdCode).select2({
			language:"zh-CN",
			placeholder : _placeholder,
			multiple : multiple,
			ajax : {
				url : WIDGET_PATH_PREFIX + url,
				type : "POST",
				delay : 400,
				data : function(params) {
					var query;
					if (params.term == null || params.term == '' || params.term == 'undefind') {
						query = {
							prdcode	:param,
							subFundSname : ""
						};
					} else {
						if (option) {// 自定义参数条件
							query = {
									assistantNM : params.term,
									queryDimission : option.queryDimission,
									cleanDele : option.cleanDele,
									subFundSname : params.term
							};
						}else{
							query = {
									prdcode	:param,
									subFundSname : params.term
							};
						}
						
					}
					return query;
				},
				dataType : "json",
				processResults : function(data) {
					var results = $.map(data, function(obj) {
						return {
							id : obj.subPrdCode,
							text : obj.subFundSname
						};
					});
					return {
						results : results
					};
				}
			},
			cache : true,
			templateSelection : function(obj) {
				return $('<span data-html="true" >' + obj.text + '</span>').tooltip();
			}
		});
	},
	// 用户
	triggerCustInfoSelect : function(custNo) {
		var _placeholder = $('#' + custNo).attr("placeholder");
		if (_placeholder == null || _placeholder == '' || _placeholder == 'undefind') {
			_placeholder = "客户名称";
		}
		$('#' + custNo).select2({
			language:"zh-CN",
			placeholder : _placeholder,
			multiple : false,
			ajax : {
				url : WIDGET_PATH_PREFIX + "queryCustInfoList.do",
				type : "POST",
				delay : 400,
				data : function(params) {
					var query;
					if (params.term == null || params.term == '' || params.term == 'undefind') {
						query = {
								custname : ""
						};
					} else {
						query = {
								custname : params.term
						};
					}
					return query;
				},
				dataType : "json",
				processResults : function(data) {
					var results = $.map(data, function(obj) {
						return {
							id : obj.custNo,
							text : obj.custName
						};
					});
					return {
						results : results
					};
				}
			},
			cache : true,
			templateSelection : function(obj) {
				return $('<span data-html="true" >' + obj.text + '</span>').tooltip();
			}
		});
	},
	//字典表
	triggerDictionarySelect : function(dicId,dicType) {
		var _placeholder = $('#' + dicId).attr("placeholder");
		if (_placeholder == null || _placeholder == '' || _placeholder == 'undefind') {
			if(dicType == 'RECEIVE_CATEGORY' ){
				_placeholder = '收款类型';
			}else if (dicType == 'TRANSFER_CATEGORY'){
				_placeholder = "划款类型";
			}else if (dicType == 'CUST_TYPE'){
				_placeholder = "客户类型";
			}
		}
		$('#' + dicId).select2({
			language:"zh-CN",
			placeholder : _placeholder,
			multiple : false,
			ajax : {
				url : WIDGET_PATH_PREFIX + "queryDictionaryList.do",
				type : "POST",
				delay : 400,
				data : function(params) {
					var query;
					if (params.term == null || params.term == '' || params.term == 'undefind') {
						query = {
								dctType : dicType 
						};
					} else {
						query = {
								dctType : params.term
						};
					}
					return query;
				},
				dataType : "json",
				processResults : function(data) {
					var results = $.map(data, function(obj) {
						return {
							id : obj.dctValue,
							text : obj.dctName
						};
					});
					return {
						results : results
					};
				}
			},
			cache : true,
			templateSelection : function(obj) {
				return $('<span data-html="true" >' + obj.text + '</span>').tooltip();
			}
		});
	},
	
	// 账户类型信息下拉
	triggerAccountTypeListSelect : function(selector,accCategory, option) {
		var _placeholder = $(selector).attr("placeholder");
		if (_placeholder == null || _placeholder == '' || _placeholder == 'undefind') {
			_placeholder = "账户类型名称";
		}
		$(selector).select2({
			language:"zh-CN",
			placeholder : _placeholder,
			multiple : false,
			ajax : {
				url : WIDGET_PATH_PREFIX + "queryAccountTypeList.do",
				type : "GET",
				delay : 400,
				cache : false,
				data : function(params) {
					var query;
					if (params.term == null || params.term == '' || params.term == 'undefind') {
						query = {
								accCategory:accCategory,
								accTypeName : ""
						};
					} else {
						query = {
								accCategory:accCategory,
								accTypeName : params.term
						};
					}
					return query;
				},
				dataType : "json",
				processResults : function(data) {
					var results = $.map(data, function(obj) {
						return {
							id : obj.accTypeId,
							text : obj.accTypeName
						};
					});
					return {
						results : results
					};
				}
			},
			templateSelection : function(obj) {
				return $('<span data-html="true" >' + obj.text + '</span>').tooltip();
			}
		});
	},
	
	// 账户类型信息下拉
	triggerAccountInfoListSelect : function(selector,accLevel, option) {
		var _placeholder = $(selector).attr("placeholder");
		if (_placeholder == null || _placeholder == '' || _placeholder == 'undefind') {
			_placeholder = "开户行";
		}
		$(selector).select2({
			language:"zh-CN",
			placeholder : _placeholder,
			multiple : false,
			ajax : {
				url : WIDGET_PATH_PREFIX + "queryBankAccountInfoList.do",
				type : "GET",
				delay : 400,
				cache : false,
				data : function(params) {
					var query;
					if (params.term == null || params.term == '' || params.term == 'undefind') {
						query = {
								accLevel:accLevel,
								accBankName : ""
						};
					} else {
						query = {
								accLevel:accLevel,
								accBankName : params.term
						};
					}
					return query;
				},
				dataType : "json",
				processResults : function(data) {
					var results = $.map(data, function(obj) {
						return {
							id : obj.accId,
							text : obj.accBankName
						};
					});
					return {
						results : results
					};
				}
			},
			templateSelection : function(obj) {
				return $('<span data-html="true" >' + obj.text + '</span>').tooltip();
			}
		});
	},
	
	// 搜索公司
	triggerCompanySelect : function(selector, option) {
		var _placeholder = $(selector).attr("placeholder");
		if (_placeholder == null || _placeholder == '' || _placeholder == 'undefind') {
			_placeholder = "管理人";
		}
		$(selector).select2({
			language:"zh-CN",
			placeholder : _placeholder,
			multiple : false,
			ajax : {
				url : WIDGET_PATH_PREFIX + "queryMatchCompany.do",
				type : "GET",
				delay : 400,
				cache : false,
				data : function(params) {
					var query;
					if (params.term == null || params.term == '' || params.term == 'undefind') {
						query = {
								companyName : ""
						};
					} else {
						query = {
								companyName : params.term
						};
					}
					return query;
				},
				dataType : "json",
				processResults : function(data) {
					var results = $.map(data, function(obj) {
						return {
							id : obj.id,
							text : obj.companyName
						};
					});
					return {
						results : results
					};
				}
			},
			templateSelection : function(obj) {
				return $('<span data-html="true" >' + obj.text + '</span>').tooltip();
			}
		});
	},
	// 搜索机构
	triggerInstSelect : function(selector, option) {
		var _placeholder = $(selector).attr("placeholder");
		if (_placeholder == null || _placeholder == '' || _placeholder == 'undefind') {
			_placeholder = "管理人";
		}
		$(selector).select2({
			language:"zh-CN",
			placeholder : _placeholder,
			multiple : false,
			ajax : {
				url : WIDGET_PATH_PREFIX + "queryMatchInst.do",
				type : "GET",
				delay : 400,
				cache : false,
				data : function(params) {
					var query;
					if (params.term == null || params.term == '' || params.term == 'undefind') {
						query = {
								instSName : ""
						};
					} else {
						query = {
								instSName : params.term
						};
					}
					return query;
				},
				dataType : "json",
				processResults : function(data) {
					var results = $.map(data, function(obj) {
						return {
							id : obj.instId,
							text : obj.instSName
						};
					});
					return {
						results : results
					};
				}
			},
			templateSelection : function(obj) {
				return $('<span data-html="true" >' + obj.text + '</span>').tooltip();
			}
		});
	}
};

$('.btn-collapse').click(function() {
    var button = $(this).find('i');
    button.toggleClass('fa-chevron-up').toggleClass('fa-chevron-down');
});

/**
 * 获取日期范围控件值数组，数组第一个值为开始日期，数组第二个值为结束日期
 * @param dateId
 */
$.fn.getDateRangeValue = function() {
	var local = {
		rangeseparator : ' - ',// 日期范围中两个日期的分割符
		dateseparator : '-'// 取值后单个日期各元素之间的分隔符
	};
	var dateVal = $(this).val();
	var data = [];
	if (dateVal) {
		var dates = dateVal.split(local.rangeseparator);
		data[0] = $.trim(dates[0].replace(/\//g, local.dateseparator));// 开始日期
		if (dates.length == 2) {
			data[1] = $.trim(dates[1].replace(/\//g, local.dateseparator));// 结束日期
		} else {
			data[1] = "";
		}
	} else {
		data[0] = "";
		data[1] = "";
	}
	return data;
};



/**
 * 改变JQgrid操作那一列的展现方式
 * @param dateId
 */
$.fn.changeJqGridOfOption = function(id) {
	var $this = $('#' + id);
	var $tds = $this.find('td[aria-describedby=' + id + '_option]');
	$.each($tds, function () {
		if ($(this).children('a').length < 4) {
			return false;
		}
		var list = '';
		for (var i = 3; i < $(this).children('a').length; i++) {
			list += $(this).children('a')[i].outerHTML;
			$($(this).children('a')[i]).addClass('remove');
		}
		var html = '<div class="btn-option" title="更多操作"><i class="fa fa-chevron-circle-right" aria-hidden="true"></i><div class="hide-option">' + list + '</div></div>';
		$(this).append(html);
		$(this).css('overflow', 'visible');
		var width = $(this).find('.hide-option').width(); 
		$(this).find('.hide-option').css('left', -width - 3);
		$(this).children('.remove').remove();
	});
};


